home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / vicdual.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  5KB  |  190 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12.  
  13.  
  14. unsigned char *vicdual_characterram;
  15. static unsigned char dirtycharacter[256];
  16.  
  17. static int palette_bank;
  18.  
  19.  
  20.  
  21. /***************************************************************************
  22.  
  23.   Convert the color PROMs into a more useable format.
  24.  
  25.   The VIC dual game board has one 32x8 palette PROM. The color code is taken
  26.   from the three most significant bits of the character code, plus two
  27.   additional palette bank bits.
  28.   The palette PROM is connected to the RGB output this way:
  29.  
  30.   bit 7 -- 22 ohm resistor  -- RED   \
  31.         -- 22 ohm resistor  -- BLUE  |  foreground
  32.         -- 22 ohm resistor  -- GREEN /
  33.         -- Unused
  34.         -- 22 ohm resistor  -- RED   \
  35.         -- 22 ohm resistor  -- BLUE  |  background
  36.         -- 22 ohm resistor  -- GREEN /
  37.   bit 0 -- Unused
  38.  
  39. ***************************************************************************/
  40. void vicdual_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  41. {
  42.     int i;
  43.     /* for b&w games we'll use the Head On PROM */
  44.     static unsigned char bw_color_prom[] =
  45.     {
  46.         /* for b/w games, let's use the Head On PROM */
  47.         0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,
  48.         0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,0xE1,
  49.     };
  50.  
  51.  
  52.     if (color_prom == 0) color_prom = bw_color_prom;
  53.  
  54.     for (i = 0;i < Machine->drv->total_colors / 2;i++)
  55.     {
  56.         int bit;
  57.  
  58.  
  59.         /* background red component */
  60.         bit = (*color_prom >> 3) & 0x01;
  61.         *(palette++) = 0xff * bit;
  62.         /* background green component */
  63.         bit = (*color_prom >> 1) & 0x01;
  64.         *(palette++) = 0xff * bit;
  65.         /* background blue component */
  66.         bit = (*color_prom >> 2) & 0x01;
  67.         *(palette++) = 0xff * bit;
  68.  
  69.         /* foreground red component */
  70.         bit = (*color_prom >> 7) & 0x01;
  71.         *(palette++) = 0xff * bit;
  72.         /* foreground green component */
  73.         bit = (*color_prom >> 5) & 0x01;
  74.         *(palette++) = 0xff * bit;
  75.         /* foreground blue component */
  76.         bit = (*color_prom >> 6) & 0x01;
  77.         *(palette++) = 0xff * bit;
  78.  
  79.         color_prom++;
  80.     }
  81.  
  82.     palette_bank = 0;
  83.  
  84.     {
  85.         extern struct GameDriver driver_heiankyo;
  86.         extern struct GameDriver driver_invinco;
  87.         extern struct GameDriver driver_digger;
  88.         extern struct GameDriver driver_tranqgun;
  89.  
  90.         /* Heiankyo Alien doesn't write to port 0x40, it expects it to default to 3 */
  91.         if (Machine->gamedrv == &driver_heiankyo)
  92.             palette_bank = 3;
  93.  
  94.         /* and many others expect it to default to 1 */
  95.         if (Machine->gamedrv == &driver_invinco ||
  96.                 Machine->gamedrv == &driver_digger ||
  97.                 Machine->gamedrv == &driver_tranqgun)
  98.             palette_bank = 1;
  99.     }
  100. }
  101.  
  102.  
  103.  
  104. WRITE_HANDLER( vicdual_characterram_w )
  105. {
  106.     if (vicdual_characterram[offset] != data)
  107.     {
  108.         dirtycharacter[(offset / 8) & 0xff] = 1;
  109.  
  110.         vicdual_characterram[offset] = data;
  111.     }
  112. }
  113.  
  114. READ_HANDLER( vicdual_characterram_r )
  115. {
  116.     return vicdual_characterram[offset];
  117. }
  118.  
  119. WRITE_HANDLER( vicdual_palette_bank_w )
  120. {
  121.     if (palette_bank != (data & 3))
  122.     {
  123.         palette_bank = data & 3;
  124.         memset(dirtybuffer,1,videoram_size);
  125.     }
  126. }
  127.  
  128.  
  129.  
  130. /***************************************************************************
  131.  
  132.   Draw the game screen in the given osd_bitmap.
  133.   Do NOT call osd_update_display() from this function, it will be called by
  134.   the main emulation engine.
  135.  
  136. ***************************************************************************/
  137. void vicdual_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  138. {
  139.     int offs;
  140.  
  141.  
  142.     if (full_refresh)
  143.     {
  144.         memset(dirtybuffer,1,videoram_size);
  145.     }
  146.  
  147.     /* for every character in the Video RAM, check if it has been modified */
  148.     /* since last time and update it accordingly. */
  149.     for (offs = videoram_size - 1;offs >= 0;offs--)
  150.     {
  151.         int charcode;
  152.  
  153.  
  154.         charcode = videoram[offs];
  155.  
  156.         if (dirtybuffer[offs] || dirtycharacter[charcode])
  157.         {
  158.             int sx,sy;
  159.  
  160.  
  161.             /* decode modified characters */
  162.             if (dirtycharacter[charcode] == 1)
  163.             {
  164.                 decodechar(Machine->gfx[0],charcode,vicdual_characterram,Machine->drv->gfxdecodeinfo[0].gfxlayout);
  165.                 dirtycharacter[charcode] = 2;
  166.             }
  167.  
  168.  
  169.             dirtybuffer[offs] = 0;
  170.  
  171.             sx = offs % 32;
  172.             sy = offs / 32;
  173.  
  174.             drawgfx(bitmap,Machine->gfx[0],
  175.                     charcode,
  176.                     (charcode >> 5) + 8 * palette_bank,
  177.                     0,0,
  178.                     8*sx,8*sy,
  179.                     &Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  180.  
  181.         }
  182.     }
  183.  
  184.  
  185.     for (offs = 0;offs < 256;offs++)
  186.     {
  187.         if (dirtycharacter[offs] == 2) dirtycharacter[offs] = 0;
  188.     }
  189. }
  190.